<#include "/common/defaultEngine.html"/>
<@pageTheme mark="${config.optimize()?string('true', 'false')}">
    <@header title="菜单管理" libs=["treeTable"]/>
    <div class="container-div">
        <div class="row">
            <div class="col-sm-12 search-collapse">
                <@f.form id="menu-form">
                    <div class="select-list">
                        <ul>
                            <li>
                                ${i18n("菜单名称")}：
                                <input type="text" class="form-control" name="name"/>
                            </li>
                            <li>
                                ${i18n("菜单状态")}：
                                <@f.select name="hide" blankValue="" blankLabel="所有" dictType="sys_show_hide" />
                            </li>
                            <li>
                                <a class="btn btn-primary btn-rounded btn-sm" onclick="$.treeTable.search()"><i class="fa fa-search"></i>&nbsp;${i18n("查询")}</a>
                                <a class="btn btn-warning btn-rounded btn-sm" onclick="opt.form.reset()"><i class="fa fa-refresh"></i>&nbsp;${i18n("重置")}</a>
                            </li>
                        </ul>
                    </div>
                </@f.form>
            </div>
            <@table id="bootstrap-tree-table">
                <@shiro.hasPermission name="sys:menu:add">
                    <a class="btn btn-success" onclick="opt.operate.add(0)">
                        <i class="fa fa-plus"></i> ${i18n("新增")}
                    </a>
                </@shiro.hasPermission>
                <@shiro.hasPermission name="sys:menu:edit">
                    <a class="btn btn-primary" onclick="opt.operate.edit()">
                        <i class="fa fa-edit"></i> ${i18n("修改")}
                    </a>
                </@shiro.hasPermission>
                <a class="btn btn-info" id="expandAllBtn">
                    <i class="fa fa-exchange"></i> ${i18n("展开/折叠")}
                </a>
                <@shiro.hasPermission name="sys:menu:clear">
                    <a class="btn btn-danger" onclick="clearRedis()"><i class="fa fa-refresh"></i>&nbsp;${i18n("刷新缓存")}</a>
                </@shiro.hasPermission>
            </@table>
        </div>
    </div>
    <@footer>
        <script type="text/javascript">
            var addFlag = "${permission.hasPermi('sys:menu:add')}";
            var editFlag = "${permission.hasPermi('sys:menu:edit')}";
            var delFlag = "${permission.hasPermi('sys:menu:del')}";
            var visible = ${permission.isPermitteds("sys:menu:edit,sys:menu:del,sys:menu:add")?string('true', 'false')};
            var datas = ${dict.getDictListJson('sys_show_hide')};
            var datas_type = ${dict.getDictListJson('sys_menu_type')};
            var datas_target= ${dict.getDictListJson('sys_menu_target')};
            var prefix = baseURL + "sys/menu";

            $(function() {

                var options = {
                    code: "id",
                    parentCode: "parentId",
                    uniqueId: "id",
                    sortName: "orderNum",              // 排序
                    expandAll: false,
                    expandFirst: false,
                    url: prefix + "/list",
                    addUrl: prefix + "/add/{id}",
                    editUrl: prefix + "/edit/{id}",
                    delUrl: prefix + "/del/{id}",
                    async: true,                 // 开启异步
                    asynUrl: prefix + "/listChild", // 点击异步请求
                    modalName: "${i18n("菜单")}",
                    columns: [
                        {field: 'selectItem', radio: true},
                        {title: "${i18n("菜单名称")}", field: 'name', width: '20%',align: "left",halign:"left", formatter: function(value, row, index) {
                                if (opt.common.isEmpty(row.icon)) {
                                    return row.name;
                                } else {
                                    return '<i class="' + row.icon + '"></i> <span class="nav-label">' + row.name + '</span>';
                                }}
                        },
                        {field: 'moduleCodes', title: "${i18n("归属模块")}", width: '10%'},
                        {field: 'orderNum', title: "${i18n("排序")}", width: '5%'},
                        {title: "${i18n("请求地址")}", field: 'url', width: '15%'},
                        {title: "${i18n("目标")}", field: 'target', width: '15%', formatter: function(value, row, index) {
                                if(row.type === 1){
                                    return opt.common.selectDictLabel(datas_target, value);
                                }
                            }
                        },
                        {title: "${i18n("类型")}", field: 'type', width: '10%', formatter: function(value, row, index) {
                                return opt.common.selectDictLabel(datas_type, value);
                            }
                        },
                        {field: 'hide',title: "${i18n("可见")}", width: '10%', formatter: function(value, row, index) {
                                return opt.common.selectDictLabel(datas, value);}
                        },
                        {field: 'perms', title: "${i18n("权限标识")}", width: '15%'},
                        {title: "${i18n("操作")}", width: '20%', class:'action', formatter: function(value, row, index) {
                                var actions = [];
                                actions.push('<a class="' + editFlag + '" href="javascript:void(0)" title="${i18n("修改")}" onclick="opt.operate.edit(\'' + row.id + '\')"><i class="fa fa-edit"></i></a> ');
                                if(row.type != 2){
                                    actions.push('<a class="' + delFlag + '" href="javascript:void(0)" title="${i18n("新增")}" onclick="opt.operate.add(\'' + row.id + '\')"><i class="fa fa-plus"></i></a> ');
                                }
                                actions.push('<a class="' + delFlag + '" href="javascript:void(0)" title="${i18n("删除")}" onclick="delMenu(\'' + row.id +'\')"><i class="fa fa-trash-o"></i></a> ');
                                return actions.join('');

                            }
                        }]
                };
                /*初始化*/
                $.treeTable.init(options);
            })

            /* 清空菜单缓存*/
            function clearRedis() {
                opt.operate.get(prefix + "/clearMenu");
            }

            function delMenu(id){
                opt.modal.confirm($.i18n.text("确定删除该条{0}信息吗?",opt.table.options.modalName) +
                    "<span style='font-weight: 600;color:red'>本删除会<span style='font-weight: 800;font-size:18px;'>彻底</span>删除菜单以下所有信息、" +
                    "<span style='font-size:18px;font-weight: 800;'>请谨慎操作!</span></span>", function() {
                    var row = $("#" + opt.table.options.id).bootstrapTreeTable('getSelections')[0];
                    var url;
                    if (opt.common.isEmpty(row)) {
                        url = opt.table.options.delUrl;
                    }else{
                        url = opt.table.options.delUrl.replace("{id}",  row[opt.table.options.uniqueId]);
                    }
                    opt.operate.get(url);
                })
            }
        </script>
    </@footer>
</@pageTheme>